package edu.pku.sei.modeler.neditor.ui;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.gef.palette.CreationToolEntry;
import org.eclipse.gef.palette.MarqueeToolEntry;
import org.eclipse.gef.palette.PaletteContainer;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteGroup;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.PaletteStack;
import org.eclipse.gef.palette.SelectionToolEntry;
import org.eclipse.gef.palette.ToolEntry;

import edu.pku.sei.modeler.model.notation.core.NotationPackage;

public class PaletteFactory {
	static public PaletteRoot createPaletteFactory(NotationEditor editor){
		PaletteRoot root = new PaletteRoot();
		root.addAll(createCategories(root,editor));
		return root;
	}
	@SuppressWarnings("unchecked")
	static private List createCategories(PaletteRoot root,NotationEditor editor) {
		List entries = new ArrayList();
		entries.add(createGeneralControlGroup(root));
		entries.add(createGraphicsDrawer(editor));
		return entries;
	}
    @SuppressWarnings("unchecked")
	private static PaletteContainer createGeneralControlGroup(PaletteRoot root) {
        PaletteGroup controlGroup = new PaletteGroup("Tool Palette");
        ToolEntry tool =null;
        tool = new SelectionToolEntry("Selection Tool");
        controlGroup.add(tool);
        //root.setDefaultEntry(tool);
        
        tool=new MarqueeToolEntry("Marquee Selection Tool");
        controlGroup.add(tool);

        return controlGroup;
    }
    private static PaletteContainer createGraphicsDrawer(NotationEditor editor) {
        PaletteDrawer drawer = new PaletteDrawer("Basic Shape Set");
        ToolEntry tool=null;
        PaletteStack stack =null;
        
        stack = new PaletteStack("Rectangle Tools","Rectangle Tools",null);
        tool = new CreationToolEntry("Rectangle","Create a Rectangle",new ShapeModelFactory(NotationPackage.TYPE_RECTANGLE,editor),null,null);
        stack.add(tool);
        tool = new CreationToolEntry("Diamond","Create a Diamond",new ShapeModelFactory(NotationPackage.TYPE_DIAMOND,editor),null,null);
        stack.add(tool);
        tool = new CreationToolEntry("Triangle","Create a Triangle",new ShapeModelFactory(NotationPackage.TYPE_TRIANGLE,editor),null,null);
        stack.add(tool);
        tool = new CreationToolEntry("RoundedRectangle","Create a RoundedRectangle",new ShapeModelFactory(NotationPackage.TYPE_ROUNDEDRECTANGLE,editor),null,null);
        stack.add(tool);
        drawer.add(stack);
        
        stack = new PaletteStack("Line Tools","Line Tools",null);
        tool = new CreationToolEntry("VerticalLine","Create a Vertical Line",new ShapeModelFactory(NotationPackage.TYPE_VERTICALLINE,editor),null,null);
        stack.add(tool);
        tool = new CreationToolEntry("HorizontalLine","Create a Horizontal Line",new ShapeModelFactory(NotationPackage.TYPE_HORIZONTALLINE,editor),null,null);
        stack.add(tool);
        drawer.add(stack);
        
        tool = new CreationToolEntry("TextObject","Create a Text Object",new ShapeModelFactory(NotationPackage.TYPE_TEXTOBJECT,editor),null,null);
        drawer.add(tool);
        
        stack = new PaletteStack("Ellipse Tools","Ellipse Tools",null);
        tool = new CreationToolEntry("Ellipse","Create a Ellipse",new ShapeModelFactory(NotationPackage.TYPE_ELLIPSE,editor),null,null);
        stack.add(tool);
        tool = new CreationToolEntry("Circle","Create a Circle",new ShapeModelFactory(NotationPackage.TYPE_CIRCLE,editor),null,null);
        stack.add(tool);
        drawer.add(stack);
        
        tool = new CreationToolEntry("Connection","Create a Connection",new ShapeModelFactory(NotationPackage.TYPE_CONNECTION,editor),null,null);
        drawer.add(tool);
/*        tool = new CreationToolEntry("Rectangle","Create a Rectangle",new ShapeModelFactory(NotationPackage.TYPE_POLYGON,editor),null,null);
        drawer.add(tool);
*/        
        return drawer;
    }
}
